home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 015a / dailybat.zip / DAILY.BAT
DOS Batch File  |  1990-08-13  |  5KB  |  131 lines

  1.  
  2.  
  3.              DOING IT DAILY KEEP YOUR SYSTEM RUNNING RIGHT
  4.              ---------------------------------------------
  5.         A Program and batch file that executes routine daily tasks.
  6.  
  7.                           By Chris DeVoney
  8.  
  9.  
  10.         You've  amassed an impressive collection of batch files and utility
  11. programs that can maintain your system, doing everything  from  backing  up
  12. your  files  to  fine-tuning  your hard disk.  But these programs do little
  13. good if you don't use them on a regular basis.  Here's a batch file/utility
  14. combination that puts those programs to work.
  15.  
  16.         Say you want to back up one directory  on Mondays  and  another  on
  17. Tuesdays  and  run  a hard disk optimizer on Wednesdays.  You could write a
  18. batch file that reads the day  of  the  week  from  the  command  line  and
  19. branches  to  the appropriate task.  But that requires you to type the day
  20. of the week and the batch file name --  it's  too  much  effort.   Instead,
  21. create  a program called DOW.COM, which reads the day of the week from your
  22. PC and supplies it to DAILY.BAT, which executes your programs accordingly.
  23.  
  24.         DOS assigns a number to each day of the week.  For example,  Sunday
  25. is 0, Monday is 1, Tuesday is 2, and so on up to Saturday, which is 6.
  26.  
  27.         The  DOW.COM program reads this number from DOS and creates an exit
  28. code, which the batch command IF ERRORLEVEL can interpret.  See Dossier for
  29. creating DOW.COM using DOS's DEBUG utility program.
  30.  
  31.  
  32.  
  33. CREATING DAILY.BAT
  34. ------------------
  35.  
  36. Next, create DAILY.BAT and place it in a subdirectory on the DOS PATH.  The
  37. following is an outline for DAILY.BAT:
  38.  
  39. @ECHO OFF
  40. CLS
  41. DOW
  42. FOR %%D IN (0 1 2 3 4 5 6) DO IF ERRORLEVEL %%D GOTO %%D
  43. :0
  44. {Insert your Sunday commands}
  45. GOTO end
  46. :1
  47. {Insert your Monday commands}
  48. GOTO end
  49. :2
  50. {Insert your Tuesday commands}
  51. GOTO end
  52. :3
  53. {Insert your Wednesday commands}
  54. GOTO end
  55. :4
  56. {Insert your Thursday commands}
  57. GOTO end
  58. :5
  59. {Insert your Friday commands}
  60. GOTO end
  61. :6
  62. {Insert your Saturday commands}
  63. GOTO end
  64. :end
  65.  
  66. The first three lines of DAILY.BAT turn ECHO off, clear the screen and  run
  67. DOW.COM  to  generate  the  day  of  the  week.  (If you use a  DOS version
  68. earlier than 3.3, omit the @ in the first line).  The FOR..IN..DO statement
  69. performs the bulk of the work.  The  numbers  in  parentheses  must  be  in
  70. ascending  order,  or  the  IF  ERRORLEVEL statement won't branch properly.
  71. After determining which day it is,  the  command  jumps  to  one  of  seven
  72. corresponding labels in the batch file.
  73.  
  74. LABEL WISELY
  75. ------------
  76. The  lines  following  each  label,  represented  by the notes in brackets,
  77. execute the tasks you want accomplished in each day.  Be sure that GOTO  end
  78. is the last line following each label.  For instance, if on Tuesdays (label
  79. :2)  you  want  DOS  to  back  up   only  those  files  you altered in the
  80. \123\SHEETS directory, the commands might be:
  81.  
  82.         :2
  83.         BACKUP C:\123\SHEETS\*.* A:/M/A
  84.         GOTO end
  85.  
  86. Be sure to include a label for each day that you  plan  to  run  the  batch
  87. file.   If  you  run the batch file on a day without a corresponding label,
  88. you'll get an error message.  To include entries for  inactive  days,  add
  89. labels  without instructions.  For example, if you don't use your computer
  90. on Saturdays and Sundays, but you want to  include  labels  for  those  days
  91. anyway, insert the following lines:
  92.  
  93.         :0
  94.         :6
  95.         GOTO end
  96.  
  97. Labels  can be entered in any order.  The :5 and Friday's commands can come
  98. before the :2 and Tuesday's commands.  After you've created groups for each
  99. day of the week, add the label :end to the end of the batch file.
  100.  
  101. DAILY.BAT can execute other batch  files  or  programs.   But  despite  its
  102. capabilities, DAILY.BAT has one major drawback:  It cannot run itself.  You
  103. must  either  adopt  the  discipline  of  running  thr program every day or
  104. automate the process and put the batch file's  name  at  the  end  of  your
  105. AUTOEXEC.BAT  file.   If you prefer to include it elsewhere in your startup
  106. file, execute the program with either DOS's COMMAND/C or  CALL(for  Version
  107. 3.3  and  later) commands  These two batch commands allow you to nest batch
  108. files , or invoke one from within another.
  109.  
  110.  
  111.                               DOSSIER
  112.                               -------
  113. DOW.COM
  114. -------
  115. Create DOW.COM with DEBUG.COM,  the  utility  program  included  with  DOS.
  116. Using  an  ASCII  text  editor, type the following lines into a file called
  117. DOW.SCR.  Press Enter at the end of each line.  (You can use  uppercase  or
  118. lowercase letters;  DEBUG doesn't care).
  119.  
  120.         N DOW.COM
  121.         E 0100 B4 2A CD 21 B4 4C
  122.         E 0106 CD 21
  123.         RCX
  124.         8
  125.         W
  126.         Q
  127.  
  128. Now exit to DOS and type:
  129.  
  130.         DEBUG < DOW.SCR
  131.